import Vue from 'vue';
import vant from 'vant';
import {Toast, Dialog} from 'vant';
// import 'vant/lib/index.css';

/**
 * 加载层
 * this.$loading();
 * this.$loadinghide();
 * */
Vue.prototype.$loading = function (message = "加载中...") {
   return new Promise(resolve => {
      resolve(Toast.loading({
         message,
         duration: 0, // 持续展示 toast
         forbidClick: true,
      }));
   });
};
Vue.prototype.$loadinghide = function () {
   Toast.clear();
};

/**
 * 失败提示
 * this.$toast.error()
 * */
Toast.error = function (_options = "加载失败") {
   let options = {
      icon: 'close',
      message: "加载失败"
   };
   if (typeof _options == "string") {
      options.message = _options;
   } else {
      options = Object.assign(options, _options);
   }
   return new Promise(resolve => {
      resolve(Toast(options));
   });
};

Vue.use(vant);